package org.jeecg.modules.utils.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.transtella.messageCenter.EnumMessageType;
import com.transtella.messageCenter.IEventManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.business.doc.business.entity.WmsInReceipt;
import org.jeecg.modules.business.job.CheckUsedJob;
import org.jeecg.modules.business.job.service.CheckService;
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "工具utils")
@RestController
@RequestMapping("/utils")
@Slf4j
public class UtilController {
    @Autowired
    private IdentifierGenerator identifierGenerator;

    @Autowired
    private SysBaseApiImpl sysBaseApi;

    @Autowired
    private CheckService checkService;


    @ApiOperation(value = "获取一个id", notes = "获取一个id")
    @GetMapping(value = "/nextId")
    public Result<Number> nextId(String tableName) {
        return Result.OK(identifierGenerator.nextId(tableName));

    }

    /**
     * 获取有效的数据字典
     * @param code
     * @return
     */
    @ApiOperation(value = "获取有效的数据字典", notes = "获取有效的数据字典")
    @GetMapping("/queryEnableDictItemsByCode")
    List<DictModel> queryEnableDictItemsByCode(@RequestParam("code") String code){
        return sysBaseApi.queryEnableDictItemsByCode(code);
    }

    /**
     * 测试定时任务--基础信息已使用状态
     *
     * @author DongPeng
     * @date 2023/12/5 18:53
     * @param null
     * @return
     */
    @ApiOperation(value = "测试定时任务--基础信息已使用状态", notes = "测试定时任务--基础信息已使用状态")
    @PostMapping("/checkUsed")
    public Result<Void> checkUsed(){
        log.info("开始更新基础数据已使用信息");
        long start = System.currentTimeMillis();
        checkService.checkUsed();
        long end = System.currentTimeMillis();
        log.info("结束更新 ------> 总耗时为: " + (end-start) + "毫秒");
        return Result.OK();
    }
}
